using Holoville.HOTween;
using Holoville.HOTween.Plugins;
using UnityEngine;

public class FlyCamera : MonoBehaviour
{
	public static FlyCamera instance;

	public GameObject pointFlyPlayer;

	public GameObject pointStart;

	public bool camIsFly;

	public bool isShaking;

	private Vector3 prevRotation;

	private void Awake()
	{
		instance = this;
	}

	private void Start()
	{
		HOTween.Init();
		OnFlyComplete();
	}

	private void OnDestroy()
	{
		instance = null;
	}

	private void StartShaking()
	{
		isShaking = true;
		int num = 10;
		Vector3 vector;
		while (true)
		{
			vector = new Vector3(prevRotation.x + (float)Random.Range(-2, 3), prevRotation.y + Random.Range(-3f, 4f), prevRotation.z);
			if (num <= 0 || Vector3.Angle(vector, base.transform.localEulerAngles) > 0.3f)
			{
				break;
			}
			num--;
		}
		HOTween.To(base.transform, 7f, new TweenParms().Prop("localRotation", new PlugQuaternion(vector)).Ease(EaseType.EaseInOutBack).OnComplete(StartShaking));
	}

	private void StopShaking()
	{
		isShaking = false;
		HOTween.Kill(base.transform);
	}

	private void OnFlyComplete()
	{
		camIsFly = false;
		prevRotation = base.transform.localEulerAngles;
		StartShaking();
	}

	public void FlyToPoint(GameObject pointFly)
	{
		if (!pointFly.transform.position.Equals(base.transform.position))
		{
			StopShaking();
			camIsFly = true;
			HOTween.To(base.transform, 2f, new TweenParms().Prop("localPosition", pointFly.transform.position).Prop("localRotation", new PlugQuaternion(pointFly.transform.localRotation)).Ease(EaseType.EaseInOutBack)
				.OnComplete(OnFlyComplete));
		}
	}

	public void FlyToStart()
	{
		FlyToPoint(pointStart);
	}

	public void FlyToPlayer()
	{
		FlyToPoint(pointFlyPlayer);
	}
}
